---
--类名: DailyTaskInfo.lua
--创建日期: 2018-3-14
--创建人: 陈小虎
--功能描述:
--修改内容：
--修改日期:
--修改人:
--修改备注:

local DailyTaskInfo = class("DailyTaskInfo")

function DailyTaskInfo:ctor()

end

function DailyTaskInfo:read(params)
	self._taskRewardProgress = {}
	if params.taskRewardProgress then
		for i, v in ipairs(params.taskRewardProgress) do
			local TaskRewardProgressTemp = {}
			TaskRewardProgressTemp.NeedProgress = v.NeedProgress -- 档位数（3、6、9）
			TaskRewardProgressTemp.NowProgress = v.NowProgress -- 盒子的累积个数
			TaskRewardProgressTemp._boxReward = {}
			for i = #v.boxReward , 1, -1 do -- v.boxReward 服务器是按照倒序给的，即：i越小，对应reward越旧
				local temp = {}
				for i3, v3 in ipairs(v.boxReward[i].loots) do
					local rewardTemp = UD:parseLootToBagItem(v3)
					table.insert( temp, rewardTemp )
				end
				TaskRewardProgressTemp._boxReward[i] = temp
			end
			table.insert(self._taskRewardProgress, TaskRewardProgressTemp)
		end

        table.sort(self._taskRewardProgress,function( a, b )
            return a.NeedProgress < b.NeedProgress
        end)

        for i, data in ipairs(self._taskRewardProgress) do
        	data.boxIndex = i
        end
	end
	-- dump( self._taskRewardProgress, " ------------------->>>> 数据", 5 )

	self._taskRefreshCounts = {}
	if params.taskRefreshCounts then
		for i, v in ipairs(params.taskRefreshCounts) do
			local value = {}
			value.RefreshNum = v.RefreshNum
			value.Pos = v.Pos
			table.insert(self._taskRefreshCounts, value)
		end
	end

	-- 特权礼包的的特权宝箱
	if params.SuperPrivilegeBoxNum then
		self._SuperPrivilegeBoxNum = params.SuperPrivilegeBoxNum
	end
	if params.CanGetSuperPrivilegeBox then
		self._CanGetSuperPrivilegeBox = params.CanGetSuperPrivilegeBox
	end
end

function DailyTaskInfo:getRewardNum()
	local num = 0
	if self._taskRewardProgress then
		for i,v in ipairs( self._taskRewardProgress ) do
			num = num + v.NowProgress
		end
	end
	return num
end 

function DailyTaskInfo:getDailyTaskProgress()
	return self._taskRewardProgress
end

function DailyTaskInfo:getTaskRewardProgress(needProgress)
	if not self._taskRewardProgress then return nil end
	for _, data in ipairs(self._taskRewardProgress) do
		if data.NeedProgress == needProgress then
			return data
		end
	end
	return nil
end

function DailyTaskInfo:getTaskRewards(needProgress, nowProgress)
	local taskRewardProgressTemp = nil
	for i,v in ipairs( self._taskRewardProgress ) do
		if tonumber( v.NeedProgress ) == tonumber(needProgress) then
			taskRewardProgressTemp = v
			break
		end
	end
	-- dump( taskRewardProgressTemp, " ------------->>>> 档位数：".. needProgress .. " ;累积次数：" .. nowProgress, 10 )
	return taskRewardProgressTemp._boxReward[nowProgress]
end

-- 获取剩余刷新次数
function DailyTaskInfo:getRefreshNum(pos)
	for _, data in ipairs(self._taskRefreshCounts or {}) do
		if data.Pos == pos then
			return data.RefreshNum
		end
	end
	return 0
end

function DailyTaskInfo:getSuperPrivilegeBoxNum()
	return self._SuperPrivilegeBoxNum
end

function DailyTaskInfo:CanGetSuperPrivilegeBox()
	return self._CanGetSuperPrivilegeBox
end

return DailyTaskInfo
